/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.com.intesal.compra.managed;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import sv.com.intesal.clases.Mensaje;
import sv.com.intesal.compra.bean.Material;
import sv.com.intesal.compra.controlador.MaterialControlador;

/**
 *
 * @author JM
 */
@ManagedBean(name = "materialQuickManaged")
@ViewScoped
public class MaterialQuickManaged implements Serializable {

    List<Material> materiales_AC;
    private Material selectedMaterial;

    public MaterialQuickManaged() {
        selectedMaterial = new Material();
        this.llenarMaterial();
    }

    public void llenarMaterial() {
        Mensaje m = new Mensaje();
        try {
            //if (this.getMateriales_AC() == null) {
            MaterialControlador mc = new MaterialControlador();
            this.setMateriales_AC(mc.getMaterialesActivo());
            //}
        } catch (Exception e) {
            m.messageError(m.getIerror());
            e.printStackTrace();
        }
    }

    public void doNothing() {
        //System.out.println("doNOTHING");
    }

    public void limpiar() {
        this.selectedMaterial = new Material();
        this.materiales_AC = null;
        this.llenarMaterial();        
    }

    /*SETTERS AND GETTERS*/
    public Material getSelectedMaterial() {
        if (selectedMaterial == null) {
            selectedMaterial = new Material();
        }
        return selectedMaterial;
    }

    public void setSelectedMaterial(Material selectedMaterial) {
        this.selectedMaterial = selectedMaterial;
    }

    public List<Material> getMateriales_AC() {
        return materiales_AC;
    }

    public void setMateriales_AC(List<Material> materiales_AC) {
        this.materiales_AC = materiales_AC;
    }
}